﻿using IDAL;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class D_Category : ICategory
    {
        public void Add(Category item)
        {
            CakeEntities db = new CakeEntities();
            db.Category.Add(item);
            db.SaveChanges();
        }

        public void Delete(int id)
        {
            CakeEntities db = new CakeEntities();
            db.Category.Remove(db.Category.Find(id));
            db.SaveChanges();
        }

        public Category FindById(int id)
        {
            return new CakeEntities().Category.Find(id);
        }

        public List<Category> GetAll()
        {
            return new CakeEntities().Category.ToList();
        }

        public void Updata(int id, Category item)
        {
            CakeEntities db = new CakeEntities();
            var data=db.Category.Find(id);
            if (data!=null)
            {
                data.CategoryName = item.CategoryName;
                data.LsView = item.LsView;
                db.SaveChanges();
            }
        }
    }
}
